using MEC;
using System.Collections.Generic;
using UnityEngine;

public class CustomSkinRainbow : MonoBehaviour
{
	public MeshRenderer[] renderers;

	public Color[] colors;

	private Transform[] rendTransforms;

	private Vector3[] localPositions;

	private void Start()
	{
		rendTransforms = new Transform[renderers.Length];
		localPositions = new Vector3[renderers.Length];
		for (int i = 0; i < renderers.Length; i++)
		{
			Renderer renderer = renderers[i];
			MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock();
			renderer.GetPropertyBlock(materialPropertyBlock);
			materialPropertyBlock.SetColor("_Color", colors[i]);
			renderer.SetPropertyBlock(materialPropertyBlock);
			Transform transform = renderer.transform;
			rendTransforms[i] = transform;
			localPositions[i] = transform.localPosition;
		}
		Timing.RunCoroutine(RainbowCoroutine().CancelWith(base.gameObject), Segment.Update);
	}

	private IEnumerator<float> RainbowCoroutine()
	{
		int index = 0;
		while (true)
		{
			for (int i = 0; i < rendTransforms.Length; i++)
			{
				rendTransforms[i].localPosition = localPositions[(index + i) % localPositions.Length];
			}
			index++;
			if (index >= rendTransforms.Length)
			{
				index = 0;
			}
			yield return Timing.WaitForSeconds(0.05f);
		}
	}
}
